package com.huan.dml;

import com.huan.Call;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class ScanDataAPI {


    //Scan 获取
    public static void scanData(String tableName) throws IOException {
        //1.获取表对象
        Connection conn = Call.conn;
        Table table = conn.getTable( TableName.valueOf( tableName ) );

        //2.构建Scan对象
        Scan scan = new Scan();

        //3.扫描表
        ResultScanner resultScanner = table.getScanner( scan );


        //4.解析 resultScanner
        for (Result result : resultScanner) {

            //5.解析result被打印
            Cell[] cells = result.rawCells();

            //6.打印数据
            for (Cell cell : cells) {
                System.out.println("CF:"+ Bytes.toString( CellUtil.cloneFamily( cell ) )
                        +",CN:"+Bytes.toString( CellUtil.cloneQualifier( cell ) ) +
                        ",Value:"+ Bytes.toString( CellUtil.cloneValue( cell ) )
                );
            }
        }
    }

    public static void main(String[] args) throws IOException {

        scanData( "stu" );
        Call.close();
    }
}
